package study.alex.resumedb.jdo;

import javax.jdo.annotations.*;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: alex
 * Date: 07.11.13
 * Time: 16:59
 * SVN $Id$
 */

@PersistenceCapable (identityType= IdentityType.APPLICATION, detachable="true")
@Extension(vendorName="DataNucleus", key="mysql-engine-type", value="MyISAM")
public class resumeHistory {

    @PrimaryKey
    @Persistent(valueStrategy= IdGeneratorStrategy.INCREMENT)
    private long id;

    @Persistent (defaultFetchGroup = "true")
    private HashSet<resumeTracker> history = new HashSet<>();

    public Set<resumeTracker> getHistory() {
        return history;
    }

    public resumeTracker registerResume(Contact aEmployer, Long aResume, GregorianCalendar date) {

        if (aResume == null) return null;

        resumeTracker res = new resumeTracker(aEmployer, date, aResume);

        return history.add(res) ? res : null;
    }

    public Set<resumeTracker> registerResume(Collection<Contact> aEmployers, Long aResume, GregorianCalendar date) {

        if (aResume == null) return null;

        Set<resumeTracker> res = new HashSet<>();

        for (Contact emp : aEmployers) {
            res.add(new resumeTracker(emp,date,aResume));
        }

        return history.addAll(res) ? res : null;
    }

}
